package com.btkjgc.service.impl;

import java.util.Enumeration;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;

import com.btkjgc.models.CartypeT;
import com.btkjgc.models.extend.CartypeModel;
import com.btkjgc.service.intf.CartypeManageService_Intf;
import com.btkjgc.utils.HibernateUtil;

@Component
public class CartypeManageService_Impl extends BaseService_Impl implements CartypeManageService_Intf
{

	@Override
	public void setListData(HttpServletRequest request, ModelAndView mv,int pageIndex, int totalRecord, 
			List<CartypeModel> cartypeModel) {
		// TODO Auto-generated method stub
		
		Enumeration<String> names = request.getParameterNames();
		while (names.hasMoreElements())
		{
			String name = names.nextElement();
			mv.addObject(name, request.getParameter(name));
		}
		
		mv.addObject("cartype_t", cartypeModel);
		
		mv.addObject("currentpage", pageIndex);
		mv.addObject("totalRecord", totalRecord);
		
	}

	@Override
	public void addCartype(CartypeT cartype) {
		// TODO Auto-generated method stub
		HibernateUtil.save(cartype);
	}

	@Override
	public void updateCartype(CartypeModel cartypeModel) {
		// TODO Auto-generated method stub
		String hql = " update from CartypeT " +
					 " set" +
					 " name='"+cartypeModel.getName()+"',"+
					 " battery_num="+cartypeModel.getBattery_num()+","+
					 " seat_num="+cartypeModel.getSeat_num()+","+
					 " unitprice="+cartypeModel.getUnitprice()+
					 " where id="+cartypeModel.getId();
		
		HibernateUtil.executeUpdate(hql);
	}
	
}